//
//  HNSH_GoodsDetailNavView.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/25.
//

#import "HNSH_GoodsDetailNavView.h"

@interface HNSH_GoodsDetailNavView ()

/* backButton */
@property (nonatomic, strong) UIButton *backButton;


@end

@implementation HNSH_GoodsDetailNavView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self configUI];
    }
    return self;
}

- (void)setFavoriteAble:(BOOL)favoriteAble {
    _favoriteAble = favoriteAble;
    self.likeButton.selected = favoriteAble;
}

- (void)configUI {
    [self addSubview:self.backButton];
    [self addSubview:self.likeButton];
    [self addSubview:self.shareButton];
}

#pragma mark lazy
- (UIButton *)backButton {
    if (!_backButton) {
        _backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _backButton.frame = CGRectMake(0, kStatusBarHeight, 63, 44);
        [_backButton setImage:[UIImage imageNamed:@"goods_detail_nav_back"] forState:UIControlStateNormal];
        WeakSelf(weakSelf);
        [[_backButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            if (weakSelf.backBlock) {
                weakSelf.backBlock();
            }
        }];
    }
    return _backButton;
}

- (UIButton *)likeButton {
    if (!_likeButton) {
        _likeButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _likeButton.frame = CGRectMake(kScreenWidth-68-44, kStatusBarHeight, 44, 44);
        [_likeButton setImage:[UIImage imageNamed:@"goods_detail_nav_like_off"] forState:UIControlStateNormal];
        [_likeButton setImage:[UIImage imageNamed:@"goods_detail_nav_like_on"] forState:UIControlStateSelected];
        WeakSelf(weakSelf);
        [[_likeButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            if (weakSelf.likeBlock) {
                weakSelf.likeBlock();
            }
        }];
    }
    return _likeButton;
}

- (UIButton *)shareButton {
    if (!_shareButton) {
        _shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _shareButton.frame = CGRectMake(kScreenWidth-44-8, kStatusBarHeight, 44, 44);
        [_shareButton setImage:[UIImage imageNamed:@"goods_detail_nav_share"] forState:UIControlStateNormal];
        WeakSelf(weakSelf);
        [[_shareButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            if (weakSelf.shareBlock) {
                weakSelf.shareBlock();
            }
        }];
    }
    return _shareButton;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
